package com.wzg.jetpack_blackbox.login;

import com.blankj.utilcode.util.ThreadUtils;
import com.wzg.jetpack_blackbox.R;
import com.wzg.jetpack_blackbox.base.INetWorkCallback;
import com.wzg.jetpack_blackbox.login.entity.LoginEntity;
import com.wzg.jetpack_blackbox.login.source.ILoginLocalDataSource;
import com.wzg.jetpack_blackbox.login.source.ILoginNetWorkDataSource;
import com.wzg.jetpack_blackbox.login.source.ILoginRepository;
import com.wzg.jetpack_blackbox.login.source.LoginLocalDataSource;
import com.wzg.jetpack_blackbox.login.source.LoginNetWorkDataSource;

public class LoginRepository implements ILoginRepository {

    private final ILoginNetWorkDataSource loginNetWorkDataSource;
    private final ILoginLocalDataSource loginLocalDataSource;


    private LoginRepository() {
        loginNetWorkDataSource = new LoginNetWorkDataSource();
        loginLocalDataSource = new LoginLocalDataSource();
    }

    public static LoginRepository getInstance() {
        return Helper.INSTANCE;
    }

    @Override
    public void save2disk(String name, String pwd) {
        ThreadUtils.getCachedPool().execute(new Runnable() {
            @Override
            public void run() {
                loginLocalDataSource.save2disk(name, pwd);
            }
        });
    }

    @Override
    public void login(String name, String pwd, INetWorkCallback<LoginEntity> callback) {
        loginNetWorkDataSource.login(name, pwd, callback);
    }


    private static final class Helper {

        private final static LoginRepository INSTANCE = new LoginRepository();

    }


}
